
import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wanxiang_app/bean/login_entity.dart';
import 'package:wanxiang_app/bean/simple_entity.dart';
import 'package:wanxiang_app/pages/my/readStep1.dart';
import 'package:wanxiang_app/utils/constant.dart';
import 'package:wanxiang_app/utils/user_util.dart';
import '../../utils/network_manager.dart';
import '../../utils/network_url.dart';
import '../../utils/toast_util.dart';
import '../../widgets/account_textField2.dart';
import '../../widgets/myappbar.dart';
import 'package:get/get.dart';
class RealNamePage extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}
class _HomeState extends State<RealNamePage> {
  String idCard = '';
  String name = '';
  @override
  void initState() {
    super.initState();
    print('iddddd11111====='+UserUtil.getUSER()!.idCard);
  }

  @override
  Widget build(BuildContext context) {
    return
      Scaffold(
        backgroundColor: Colors.white,
        appBar: MyAppBar(context: context, title: '实名认证',hasLeading: true,),
        body: _content(),
      );
  }
  Widget _content(){
    return Container(
      padding: EdgeInsets.fromLTRB(20.w, 22.h, 30.w, 0),
      child: Stack(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [

              Text('认证后可进行商品交易',style: TextStyle(
                color: Color(0xFF666666),
                fontSize: 13.sp,
              ),),

              Container(
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(6.r),
                    color: Color(0xFFF9F9F9)
                ),
                height: 48.h,
                margin: EdgeInsets.only(
                  top: 15.h,
                ),
                child: AccountEdit2Text(
                  //获取返回的输入内容
                  hitText: '请输入姓名',
                  inputColor: 0xFFF9F9F9,
                  contentStrCallBack: (content) {
                    name = content;
                  }, key: ValueKey('name'),
                ),
              ),
              Container(
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(6.r),
                    color: Color(0xFFF9F9F9)
                ),
                height: 48.h,
                margin: EdgeInsets.only(
                  top: 15.h,
                ),
                child: AccountEdit2Text(
                  //获取返回的输入内容
                  hitText: '请输入身份证号',
                  inputColor: 0xFFF9F9F9,
                  contentStrCallBack: (content) {
                    idCard = content;
                  }, key: ValueKey('number'),
                ),
              ),


            ],
          ),
          Positioned(
              bottom: 78.h,
              child: InkWell(
                onTap: (){
                  _getService();
                },
                child: Container(
                  alignment: Alignment.center,
                  width: MediaQuery.of(context).size.width - 50.w,
                  height: 42.h,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(22.r),
                    color: Color(0xFF007BE5),
                  ),
                  child: Text('提交',style: TextStyle(
                      color: Colors.white,
                      fontSize: 14.sp
                  ),),
                )
              ) )
        ],
      ),
    );
  }

  void _getService(){

    if(name.isEmpty){
      ToastUtil.show('请输入姓名');
        return;
    }
    if(idCard.isEmpty){
      ToastUtil.show('请输入身份号');
      return;
    }
    DioManager.getInstance().post(ServiceUrl.realName,{
      'user_name':UserUtil.getUSER()?.userName,
      'name':name,
      'idcard':idCard,
    }, (data) async {
      SimpleEntity bannerEntity = SimpleEntity.fromJson(jsonDecode(data));
      if(bannerEntity.code==200){
        UserUtil.getUSER()?.idCard = idCard;
        // LoginData loginData = UserUtil.getUSER()!;
        // loginData.idCard = idCard;
        // UserUtil.saveUSER(loginData);
        Get.back(result: -1);
      }else{
        ToastUtil.show("姓名和身份证校验失败，请认真查验输入的姓名和身份证是否正确!");
      }
    }, (error) {
      // ToastUtil.show(error);
    },needErrorMsg: false);
  }

}

